import cgi
import uuid
import datetime
from google.appengine.ext import db

class Group(db.Model):
  name = db.StringProperty()
  threads = db.IntegerProperty()
  
  def toObject(self):
    if (self.is_saved()):
      return {'key': self.key(), 'name' : str(self.name), 'threads' : self.threads}
    else:
      return {'name' : str(self.name), 'threads' : self.threads}
      
  

class Post(db.Model):
  threadkey = db.StringProperty()
  subject = db.StringProperty()
  author = db.StringProperty()
  group = db.StringProperty()
  timestamp = db.DateTimeProperty(auto_now_add=True)
  message = db.StringProperty()

class Thread(db.Model):
  groupkey = db.StringProperty()
  subject = db.StringProperty()
  author = db.StringProperty()
  group = db.StringProperty()
  timestamp = db.DateTimeProperty(auto_now_add=True)

  def toObject(self):
    if (self.is_saved()):
      return {'key': self.key(), 'groupkey': str(self.groupkey), 'subject' : str(self.subject), 'author' : str(self.author), 'group' : str(self.group), 'timestamp' : str(timestamp)}
    else:
      return {'groupkey': str(self.groupkey), 'subject' : str(self.subject), 'author' : str(self.author), 'group' : str(self.group)}
